﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace OttoEngineSimulation
{
    public class Piston : Control
    {
        private int kolbenBreite = 30;
        private int kolbenHoehe = 35;        
        Point kolbenPosition;
        Point kolbenGroessenPunkt;
        Rectangle kolben;

        private int stangenBreite = 10;
        private int stangenHoehe = 40;
        Point stangePosition;
        Point stangenGroesenPunkt;

        public Piston()
        {           
            this.Size = new Size(new Point(200, 200));
            this.BackColor = Color.Blue;
            this.BerechneGroesse();
            this.ZeichneKolbenkopf();
            this.ZeichneStange();
        }

        public void ZeichneKolbenkopf()
        {
            Graphics g = this.CreateGraphics();
            int kolbenPositionX = this.Location.X + 10;
            int kolbenPositionY = this.Location.Y + 20;
            this.kolbenPosition = new Point(kolbenPositionX, kolbenPositionY);
            this.kolben = new Rectangle(this.kolbenPosition, new Size(this.kolbenGroessenPunkt));
            g.DrawRectangle(new Pen(Color.Red), this.kolben);
        }

        private void BerechneGroesse()
        {
            this.kolbenGroessenPunkt = new Point(this.kolbenBreite, this.kolbenHoehe);
            this.stangenGroesenPunkt = new Point(this.stangenBreite, this.stangenHoehe);
        }

        private void ZeichneStange()
        {
            Graphics g = this.CreateGraphics();
            int stangenPositionX = this.kolben.X + 10;
            int stangenPositionY = this.kolben.Bottom;
            this.stangePosition = new Point(stangenPositionX, stangenPositionY);
            Rectangle stange = new Rectangle(this.stangePosition, new Size(this.stangenGroesenPunkt));
            g.DrawRectangle(new Pen(Color.Red), stange);
        }      
    }
}
